package cn.yl.caner.dao;

import java.sql.Connection;
import java.sql.SQLException;


import javax.sql.DataSource;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import cn.yl.caner.domain.LoginData;
import cn.yl.caner.utils.DataSourceUtils;
import cn.yl.caner.utils.MyDataSourceUtils;

public class LoginDao {
	public LoginData loginAccount(LoginData logindata) throws SQLException {
	//账号密码对比数据库
		Connection con = MyDataSourceUtils.getCurrentConnection();
		DataSource source = DataSourceUtils.getDataSource();
		QueryRunner q = new QueryRunner(source);
		String username = logindata.getAccount();
		System.out.println(username);
		String sql = "select * from account where username =?";
		 LoginData loginAccount = q.query(con,sql,new BeanHandler<LoginData>(LoginData.class),username);
		 if(loginAccount == null) {
			 LoginData  la = new LoginData();
			 la.setPassword("密码错误");
			 return la;
			 
		 }
		 return loginAccount;
	}	
}

